from __future__ import with_statement


class Limits(object):

    def __init__(self, cachebytes):
        self.max_sort_create_index = (cachebytes * 0.2)
        self.min_examined_create_index = 500
        self.ratio_create_index = .75
        self.max_skipped_create_index = 10000
        self.max_bookmark_lookup = 1000
        self.max_index_score = 10000
        self.server_obj_timeout = 5 * 60
        self.server_row_page_bytes = 64 * 1024
        self.max_locks = 5000

    def index_where(self, examined, returned):
        if examined == 0:
            return False

        ratio = returned / examined
        skipped = examined - returned
        return ((examined > self.min_examined_create_index) and
                ((ratio < self.ratio_create_index) or
                (skipped > self.max_skipped_create_index)))
